//
//  SNMYLSCollectionViewCell.m
//  ZhuoxinAgriculture
//
//  Created by stone on 16/12/11.
//  Copyright © 2016年 stone. All rights reserved.
//

#import "SNMYLSCollectionViewCell.h"
#import "Masonry.h"
@interface SNMYLSCollectionViewCell()
/** imageView */
@property (weak, nonatomic) UIImageView * iconImageView;

@end
@implementation SNMYLSCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addViews];
        [self setupUI];
    }
    return self;
}
- (void)addViews
{
    
    
    UIImageView * iconImageView = ({
        UIImageView * imageView = [[UIImageView alloc] init];
        //        imageView.backgroundColor = [UIColor colorWithWhite:0.5 alpha:1.0];
        UIImage * image = [UIImage imageNamed:@"生产计划"];
        imageView.image = image;
        
        // [self addSubview:imageView];
        // [self.view addSubview:imageView];
        [self.contentView addSubview:imageView];
        
        
        
        imageView;
    });
    self.iconImageView = iconImageView;
    
    
    
    UILabel * titleLabel = ({
        UILabel * label = [[UILabel alloc] init];
        /** GPU 优化 */
        //        label.opaque = YES;
        //        label.backgroundColor = [UIColor whiteColor];
        //        label.layer.masksToBounds = YES;
        //------------------------------
        label.numberOfLines = 0;
        label.textColor = [UIColor blackColor];
        label.textAlignment = NSTextAlignmentCenter;
        label.text = @"我的组织";
        label.font = [UIFont systemFontOfSize:12];
        
        // [self addSubview:label];
        // [self.view addSubview:label];
        [self.contentView addSubview:label];
        
        
        label;
    });
    self.titleLabel = titleLabel;
}
- (void)setupUI
{
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker * make) {
        //        make.left.mas_equalTo(self.contentView.mas_left).offset(0);
        //        make.right.mas_equalTo(self.contentView.mas_right).offset(0);
        make.centerX.mas_equalTo(self.contentView.mas_centerX).offset(0);
        
        make.bottom.mas_equalTo(self.contentView.mas_bottom).offset(-20);
        
        //        make.width.mas_equalTo(50);
        //        make.height.mas_equalTo(50);
    }];
    
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker * make) {
        //        make.left.mas_equalTo(self.contentView.mas_left).offset(0);
        //        make.right.mas_equalTo(self.contentView.mas_right).offset(0);
        make.centerX.mas_equalTo(self.contentView.mas_centerX).offset(0);
        make.bottom.mas_equalTo(self.titleLabel.mas_top).offset(-14);
        
        make.width.mas_equalTo(25);
        make.height.mas_equalTo(25);
        
    }];
    
    
}
- (void)configWithTitle:(NSString *)title imageName:(NSString *)imageName{
    self.titleLabel.text = title;
    UIImage * image = [UIImage imageNamed:imageName];
    self.iconImageView.image = image;
    [self.iconImageView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(image.size.width);
        make.height.mas_equalTo(image.size.height);
    }];
    
}
@end
